using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories;
using Matrix.ServiceDiscovery.Entities;
using Matrix.ServiceDiscovery.Enums;

namespace Matrix.ServiceDiscovery.Repositories
{
    /// <summary>
    /// 服务实例仓储接口
    /// </summary>
    public interface IServiceInstanceRepository : IRepository<ServiceInstance, Guid>
    {
        Task<ServiceInstance?> GetByInstanceIdAsync(string instanceId, bool includeDetails = false, CancellationToken cancellationToken = default);

        Task<List<ServiceInstance>> GetByServiceNameAsync(string serviceName, bool includeDetails = false, CancellationToken cancellationToken = default);

        Task<List<ServiceInstance>> GetByServiceIdAsync(Guid serviceId, bool includeDetails = false, CancellationToken cancellationToken = default);

        Task<List<ServiceInstance>> GetHealthyInstancesAsync(string serviceName, bool includeDetails = false, CancellationToken cancellationToken = default);

        Task<List<ServiceInstance>> GetUnhealthyInstancesAsync(string serviceName, bool includeDetails = false, CancellationToken cancellationToken = default);

        Task<List<ServiceInstance>> GetByRegionAsync(string region, bool includeDetails = false, CancellationToken cancellationToken = default);

        Task<List<ServiceInstance>> GetByZoneAsync(string zone, bool includeDetails = false, CancellationToken cancellationToken = default);

        Task<List<ServiceInstance>> GetByTagAsync(string tag, bool includeDetails = false, CancellationToken cancellationToken = default);

        Task<bool> ExistsByInstanceIdAsync(string instanceId, CancellationToken cancellationToken = default);

        Task<int> GetHealthyCountAsync(string serviceName, CancellationToken cancellationToken = default);

        Task<int> GetTotalCountAsync(string serviceName, CancellationToken cancellationToken = default);

        Task<List<ServiceInstance>> GetInstancesNeedingHeartbeatAsync(DateTime beforeTime, bool includeDetails = false, CancellationToken cancellationToken = default);
    }
}